var gulp = require('gulp');
gulpLoadPlugins = require('gulp-load-plugins'),
    plugins = gulpLoadPlugins();

//js文件分别单独压缩
gulp.task('minify', function () {
    gulp.src('src/js/*.js')
        .pipe(plugins.uglify())
        .pipe(plugins.rename({suffix: '.min'}))
        .pipe(gulp.dest('dest/js'))
        .pipe(plugins.connect.reload());
});
gulp.task('css', function() {
    return gulp.src('src/css/*.css')
        .pipe(plugins.cssnano())
        .pipe(plugins.rename({suffix: '.min'}))
        .pipe(gulp.dest('dest/css'))
        .pipe(plugins.connect.reload());
});
gulp.task('html', function(){
    gulp.src('example/*.html')
        .pipe(gulp.dest('dest'))
        .pipe(plugins.connect.reload());
});
gulp.task('watch', function () {
    gulp.watch('./src/js/*.js',['minify']);
    gulp.watch('./src/css/*.css',['css']);
    gulp.watch('./example/*.html',['html']);
    gulp.watch('./example/*.json',['copy-json']);
});
//copy data to dest
gulp.task('copy-json',function () {
    gulp.src('example/*.json')
        .pipe(gulp.dest('dest/data'));
});
//创建一个http服务，并对服务进行配置
gulp.task('webserver', function () {
    plugins.connect.server({
        port: 8080,
        root: 'dest',
        livereload: true
    });
});
gulp.task('default', ['minify','css','html','copy-json','watch','webserver']);
